package movies.repositoryHibernate;

import java.util.List;
import movies.domain.ArticleCategory;
import movies.repository.IArticleCategoryRepository;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author Hanna_Aliakseichykava
 */
public class ArticleCategoryRepository extends HibernateDaoSupport
implements IArticleCategoryRepository{

    @Override
    public ArticleCategory getArticleCategoryById(int id) {
        List < ArticleCategory > articleCategories = getHibernateTemplate().
             findByNamedQuery("GetArticleCategoryById", id);

        if (articleCategories.size() == 1) {
            return articleCategories.get(0);
        } else {
            return null;
        }
    }

    @Override
    public ArticleCategory getArticleCategoryByName(String name) {
        List < ArticleCategory > articleCategories = getHibernateTemplate().
             findByNamedQuery("GetArticleCategoryByName", name);

        if (articleCategories.size() == 1) {
            return articleCategories.get(0);
        } else {
            return null;
        }
    }

    @Override
    public List<ArticleCategory> getAllArticleCategories() {
        List < ArticleCategory > articleCategories = getHibernateTemplate().
             findByNamedQuery("GetAllArticleCategories");

        if (articleCategories.size() > 0) {
            return articleCategories;
        } else {
            return null;
        }
    }

}
